package com.tamecode.resource;

import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.util.FileCopyUtils;

import java.io.IOException;

/**
 * @Author: LiQiongchao
 * @Date: 2021/8/4 22:03
 */
public class EncodedResourceExample {

    public static void main(String[] args) throws IOException {
        // 使用相对路径读取文件
        ClassPathResource resource = new ClassPathResource("conf/file1.txt");
        // 使用 EncodedResource 读取
        EncodedResource encodedResource = new EncodedResource(resource, "UTF-8");
        String string = FileCopyUtils.copyToString(encodedResource.getReader());
        System.out.println(string);
    }

}
